(library (templates vocabulary)
  (export templatize
          render-voc-entry
          vocabulary-overview)
  (import
   (except (rnrs base) let-values)
   (only (guile)
         lambda* λ
         error
         display
         with-output-to-string)
   ;; SRFIs
   (prefix (srfi srfi-1) srfi-1:)
   ;; standard web library
   (web request)
   (web response)
   (web uri)
   (prefix (logging) log:)))


(define render-voc-entry
  (λ (voc-entry)
    `(tr
      (td ,(with-output-to-string
             (λ ()
               (display (srfi-1:first voc-entry)))))
      (td ,(with-output-to-string
             (λ ()
               (display (srfi-1:second voc-entry)))))
      (td ,(with-output-to-string
             (λ ()
               (display (srfi-1:third voc-entry))))))))


(define vocabulary-overview
  (λ (request body vocabulary)
    (log:debug "template: vocabulary-overview")
    `((h1 "Overview")
      (table
       (tr (th "first language")
           (th "phonetic script")
           (th "second language"))
       ,@(map (λ (voc-entry) (render-voc-entry voc-entry))
              vocabulary)))))
